#include"comm.hpp"
#include"log.hpp"
using namespace std;

int main(){
    //创建信道
    Init init;
    Log log;
    //打开信道
    int fd=open(FIFO_FILE,O_RDONLY);

    if(fd<0){
        log(Fatal,"open","string error: s%, error code: ",strerror(errno),errno);
        exit(FIFO_OPEN_ERR);
    }
    
    log.Enable(Onefile);
    log(Info,"Info");
    log(Debug,"debug");
    log(Warning,"warning");
    log(Error,"error");
    log(Fatal,"fatal");

    log.Enable(Classfile);
    log(Info,"Info");
    log(Debug,"debug");
    log(Warning,"warning");
    log(Error,"error");
    log(Fatal,"fatal");

    log.Enable(Screen);
    //接收数据
    while(true){
        char buffer[1024]={0};
        int x=read(fd,buffer,sizeof(buffer));
        if(x>0){
            buffer[x]=0;//\0的ascII码是0
            cout<<"client say# "<<buffer<<endl;
        }else if(x==0){
            cout<<"client quit! me too. "<<endl;
            break;
        }else{
            break;
        }
    }

    close(fd);
    return 0;
}